let oldArrayMethods = Array.prototype;
export const arrayMethods = Object.create(oldArrayMethods);

const methods = [
  "push",
  "pop",
  "shift",
  "unshift",
  "splice",
  "sort",
  "reverse",
];

for (let i = 0; i < methods.length; i++) {
  const method = methods[i];
  arrayMethods[method] = function (...args) {
    const ob = this.__ob__;
    console.log("数组发生变化");
    oldArrayMethods[method].apply(this, args);
    let inserted;
    switch (method) {
      case "push":
      case "unshift":
        inserted = args;
        break;
      case "splice":
        inserted = args.slice(2);
        break;
    }
    console.log("🚀 ~ inserted:", inserted);
    if (inserted) ob.observeArray(inserted);
  };
}
arrayMethods.__proto__ = methods;
